class Wiki < ActiveRecord::Base
  validates_presence_of :subdomain
  validates_format_of :subdomain, :with => /^[A-Za-z0-9-]+$/, :message => "The subdomain can only contain alphanumeric characters and dashes."
  validates_uniqueness_of :subdomain, :case_sensitive => false
  validates_exclusion_of :subdomain, :in => %w( support blog www billing support help api ), :message => "The subdomain <strong>{{value}}</strong> is reserved and unavailable."
  before_validation :downcase_subdomain
  
  validates_presence_of :title
  has_many :pages
  
  protected
  
  def downcase_subdomain
    self.subdomain.downcase! if attribute_present?('subdomain')
  end
end
